 #!/bin/bash

origin_username="tom"
correct_password="tom"

while echo -n "Localhost Login:";read username;echo -n "Password:";read -s password;do
    if [ $origin_username == $username ] && [ $correct_password == $password ];
        then
            echo -e "\n\n\nWelcome $origin_username!"
            echo -e "\n$(uname -r)"
            if [ "$(tail -n1 loginerr.log)" != "" ];
                then
                    echo -e "\nLast fail log: $(tail -n1 loginerr.log)"
            fi
            if [ "$(tail -n1 login.log)" != "" ];
                then
                    echo -e "\nLast success log: $(tail -n1 login.log)"
            fi
            echo "$(date) $(tty)" >>login.log
            cat /dev/null > loginerr.log
            break
    else
        echo -e "\n\nLogin incorrect\n"
        echo "$(date) $(tty)" >>loginerr.log
        # >：表示输出，会覆盖文件原有的内容
        # >>：表示追加，会将内容追加到已有文件内容的末尾
        """
    fi
done